package whf.framework.entity.decorator;

import java.io.Serializable;
import java.sql.Timestamp;

import org.jdom.Element;

import whf.framework.entity.Entity;
import whf.framework.exception.PropertyException;
import whf.framework.security.entity.Dept;
import whf.framework.security.entity.User;

/**
 * 用于显示的包装类<br>
 * 一般的实现类中接受一个带参数的构造器 封装后用以将同一个属性使用不同的方式展现出来
 * 
 * @author wanghaifeng
 * @create Oct 8, 2006 10:18:31 PM
 * 
 */
public abstract class EntityWrapper implements Entity {

	protected Entity bo;

	public EntityWrapper(Entity bo) {
		this.bo = bo;
	}

	/**
	 * @modify wanghaifeng Oct 8, 2006 10:19:23 PM
	 * @return 返回主键
	 */
	public long getId() {
		return bo.getId();
	}

	public String getCode() {
		return bo.getCode();
	}

	/**
	 * @modify wanghaifeng Oct 8, 2006 10:19:27 PM
	 * @return 显示名称
	 */
	public String getName() {
		return bo.getName();
	}

	public String getRemarks() {
		return bo.getRemarks();
	}

	/**
	 * 获取属性
	 * 
	 * @modify wanghaifeng Dec 29, 2006 2:47:17 PM
	 * @param propertyName
	 * @return
	 * @throws PropertyException
	 */
	public Object getProperty(String propertyName) throws PropertyException {
		return bo.getProperty(propertyName);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#cloneProperties(java.lang.Object)
	 */
	public void cloneProperties(Object source) throws PropertyException {
		bo.cloneProperties(source);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Comparable#compareTo(T)
	 */
	public int compareTo(Object o) {
		return bo.compareTo(o);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#getCreateBy()
	 */
	public User getCreateBy() {
		return bo.getCreateBy();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#getCreateDate()
	 */
	public Timestamp getCreateDate() {
		return bo.getCreateDate();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#getDept()
	 */
	public Dept getDept() {
		return bo.getDept();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#getLastUpdate()
	 */
	public Timestamp getUpdateDate() {
		return bo.getUpdateDate();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#getUpdateBy()
	 */
	public User getUpdateBy() {
		return bo.getUpdateBy();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#isActive()
	 */
	public boolean isActive() {
		return bo.isActive();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setActive(boolean)
	 */
	public void setActive(boolean active) {
		bo.setActive(active);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setCode(java.lang.String)
	 */
	public void setCode(String code) {
		bo.setCode(code);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setCreateBy(whf.framework.auth.entity.User)
	 */
	public void setCreateBy(User createBy) {
		bo.setCreateBy(createBy);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setCreateDate(java.sql.Timestamp)
	 */
	public void setCreateDate(Timestamp createDate) {
		bo.setCreateDate(createDate);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setDept(whf.framework.auth.entity.Dept)
	 */
	public void setDept(Dept dept) {
		bo.setDept(dept);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setId(long)
	 */
	public void setId(long id) {
		bo.setId(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setLastUpdate(java.sql.Timestamp)
	 */
	public void setUpdateDate(Timestamp lastUpdate) {
		bo.setUpdateDate(lastUpdate);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setName(java.lang.String)
	 */
	public void setName(String name) {
		bo.setName(name);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setProperty(java.lang.String,
	 *      java.lang.Class, java.lang.String)
	 */
	public void setProperty(String propertyName, Class propertyType,
			String value) throws PropertyException {
		bo.setProperty(propertyName, propertyType, value);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setProperty(java.lang.String,
	 *      java.lang.Object)
	 */
	public void setProperty(String propertyName, Object value)
			throws PropertyException {
		bo.setProperty(propertyName, value);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setRemarks(java.lang.String)
	 */
	public void setRemarks(String remarks) {
		bo.setRemarks(remarks);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#setUpdateBy(whf.framework.auth.entity.User)
	 */
	public void setUpdateBy(User updateBy) {
		bo.setUpdateBy(updateBy);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see whf.framework.entity.IBaseBO#toDom()
	 */
	public Element toXmlElement() throws PropertyException {
		return bo.toXmlElement();
	}

	public boolean idEquals(Entity bo){
		if(bo.getClass() != this.getClass()) return false;
		if(bo == null || this.getId() == 0 || bo.getId() == 0){
			return false;
		}
		return this.getId() == bo.getId();
	}

	public String getDisplayName() {
		return this.getName();
	}

	public Serializable getPrimaryKey() {
		return this.getId();
	}

	public String getPropertyDisplay(String propertyName)
			throws PropertyException {
		return this.getPropertyDisplay(propertyName);
	}
	
}
